<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@ page import="java.util.List"%>	
<%@ page import="java.util.ArrayList"%>	
<%@ page import="net.sf.json.JSONArray" %>
<%@ page import="org.limp.basework.Table"%>	
<%@ page import="org.limp.basework.Column"%>	
<%@ page import="org.limp.basework.analyzer.TableRegisterCenter"%>
<%@ page import="jt.classic.system.table.ColumnJsonBean" %>
<%@ page import="jt.classic.system.utils.SystemTool"%>
<%
    String tname = request.getParameter("tname");

	TableRegisterCenter center = TableRegisterCenter.getInstance();
		if(center.containsTable(tname)){
		Table table = center.findTable(tname);
		
		List list = table.columns();
		
		List resultList = new ArrayList();
		
		if(list != null && !list.isEmpty()){
		    for(int i=0;i<list.size();i++){
		    	Column column = (Column)list.get(i);
		    	
		    	ColumnJsonBean bean = new ColumnJsonBean();
		    	bean.setName(column.getName());
		    	bean.setFname(column.getFormName());
		    	bean.setKey(column.isPremaryKey());
		    	bean.setLength(column.length());
		    	bean.setMemo(column.getDescription());
		    	bean.setType(column.getType().toString());
		    	
		    	resultList.add(bean);
		    }
		}
		
		JSONArray jsonArray = JSONArray.fromObject(resultList);
		
		String jsonString = "{\"totalCount\":\"" + resultList.size() + "\",\"columnList\":";
	    jsonString += jsonArray.toString();
	    jsonString += "}";

    	request.setAttribute("result", jsonString);
    	
    	SystemTool.returnJson(request, response);
	}
%>